home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / optivc32 / veclib.h < prev    next >
C/C++ Source or Header  |  1999-03-06  |  7KB  |  202 lines

  1. /*  VecLib.h
  2.  
  3.   vector management functions.
  4.  
  5.   Contains the basic definitions for VectorLib.
  6.  
  7.   Copyright (c) 1996-1999 by Martin Sander
  8.   All Rights Reserved.
  9. */
  10.  
  11. #ifndef __VECLIB_H
  12. #define __VECLIB_H
  13.  
  14. /*    #define V_trapIntError 1   */
  15.            /*  activate this line, if you wish to generate an error
  16.                message and/or terminate program execution in case
  17.                of INTEGER OVERFLOW or INTEGER DOMAIN errors!
  18.                Additionally, you have to make one call to
  19.                V_setIntErrorHandling with either ierrNote or
  20.                ierrAbort as argument.    */
  21.  
  22. #include <stdio.h>
  23. #ifdef __BORLANDC__
  24.        /* the following statements apply to
  25.           VectorLib for Borland C++ */
  26.     #ifdef _Windows
  27.         #define _WINDOWS
  28.         #include <windows.h>
  29.     #else
  30.         #include <alloc.h>
  31.     #endif
  32.     #if defined (V_useHUGE) || defined (__HUGE__)
  33.         #define V_HUGE 1
  34.     #endif   /* use the HUGE library within the memory model LARGE */
  35.  
  36.     #if defined( V_HUGE )
  37.          #define   V_DATAPTR  huge
  38.          #define   _VFAR      far
  39.          typedef   unsigned long   ui;
  40.     #else
  41.          #if defined __TINY || defined __SMALL__ || defined __MEDIUM__
  42.              #if defined(_RTLDLL) || defined(_CLASSDLL)
  43.                  #error Must use static BC Runtime Library with OptiVec in models TINY, SMALL, MEDIUM
  44.              #endif
  45.              #define   V_DATAPTR near    /* even in case of DS!=SS  */
  46.              #define   _VFAR     near
  47.          #elif defined __FLAT__
  48.              #define  _VFAR
  49.              #define  V_DATAPTR
  50.          #else
  51.              #define   V_DATAPTR far
  52.              #define   _VFAR     far
  53.          #endif
  54.          typedef   unsigned int    ui;
  55.     #endif
  56.     #if (__BORLANDC__ >= 0x450)
  57.          #define __vf _RTLENTRY _EXPFUNC
  58.     #else
  59.          #define __vf  _Cdecl _FARFUNC
  60.     #endif
  61.     #pragma option -a-  /* avoid insertion of dummy bytes */
  62.     typedef  struct { long Lo, Hi; }  quad;  /* "quadruple int", 64 bit */
  63.     #if !defined( _CMATH_DEFS )
  64.        typedef long double  extended; /* Borland C supports IEEE 80-bit real numbers */
  65.        typedef struct {float    Re, Im;} fComplex;
  66.        typedef struct {double   Re, Im;} dComplex;
  67.        typedef struct {extended Re, Im;} eComplex;
  68.        typedef fComplex fcomplex;
  69.        typedef dComplex dcomplex;
  70.        typedef eComplex ecomplex;  // tolerate all-minuscule
  71.        #define _CMATH_DEFS
  72.     #endif
  73.     #pragma option -a.   /* restore default data packing  */
  74.  
  75. #else  /* the following definitions apply to
  76.           VectorLib for Microsoft's Visual C++ and for
  77.           VectorLib for Powersoft's Optima++ */
  78.     #if !defined(_WIN32)
  79.         #error ERROR: Only Win32 target supported!
  80.     #endif
  81.     #pragma pack(push,1)  /* pack structs without dummy bytes */
  82.     #ifdef _MSC_VER
  83.         #include <windows.h>
  84.     #else    /* Optima++ */
  85.         #define _WINDOWS
  86.     #endif
  87.     #define __vf  __cdecl
  88.     #define   _VFAR
  89.     #define   V_DATAPTR
  90.     typedef  unsigned int  ui;
  91.     typedef  struct { long Lo, Hi; }  quad;  /* "quadruple int", 64 bit */
  92.     #if !defined( _CMATH_DEFS )
  93.        typedef  double extended; /* Visual C++ and Optima++ do not
  94.                                     support 80-bit IEEE numbers.
  95.                                     So make extended equal to double. */
  96.        typedef struct {float    Re, Im;} fComplex;
  97.        typedef struct {double   Re, Im;} dComplex;
  98.        typedef dComplex                  eComplex;
  99.        #define _CMATH_DEFS
  100.        typedef fComplex fcomplex;
  101.        typedef dComplex dcomplex;
  102.        typedef eComplex ecomplex;  // tolerate all-lower case
  103.     #endif
  104.     #pragma pack(pop)   /* restore default packing */
  105. #endif    /*  Borland C/C++, Visual C++, or Optima++ */
  106.  
  107. typedef   char           V_DATAPTR *    biVector;
  108. typedef   short          V_DATAPTR *    siVector;
  109. typedef   int            V_DATAPTR *    iVector;
  110. typedef   long           V_DATAPTR *    liVector;
  111. typedef   quad           V_DATAPTR *    qiVector;
  112. typedef   unsigned char  V_DATAPTR *    ubVector;
  113. typedef   unsigned short V_DATAPTR *    usVector;
  114. typedef   unsigned int   V_DATAPTR *    uVector;
  115. typedef   unsigned long  V_DATAPTR *    ulVector;
  116. typedef   ui             V_DATAPTR *    uiVector;
  117. typedef   float          V_DATAPTR *    fVector;
  118. typedef   double         V_DATAPTR *    dVector;
  119. typedef   extended       V_DATAPTR *    eVector;
  120. typedef   fComplex       V_DATAPTR *    cfVector;
  121. typedef   dComplex       V_DATAPTR *    cdVector;
  122. typedef   eComplex       V_DATAPTR *    ceVector;
  123. #undef V_DATAPTR
  124.  
  125. #ifdef __cplusplus
  126. extern "C" {
  127. #endif
  128.  
  129. /** Allocation of memory is specific for the respective data type and
  130.     is consequently included in VFstd.h etc.
  131.     Only VBI_vector, VBI_vector0, VUB_vector, and VUB_vector0 are
  132.     included here. (This is left over from previous versions in which
  133.     no other functions were defined for biVectors and  ubVectors.)      */
  134.  
  135. biVector __vf VBI_vector( ui size );
  136. biVector __vf VBI_vector0( ui size );
  137. ubVector __vf VUB_vector( ui size );
  138. ubVector __vf VUB_vector0( ui size );
  139.  
  140. /*    Freeing memory is the same for all data types: */
  141. void  __vf  V_free( void _VFAR *X );
  142. void  __vf  V_freeAll( void );  /* frees all vectors allocated by V.._vector */
  143. void  __vf  V_nfree( unsigned numfree,...); /* e.g., V_nfree( 2, X, Y ); */
  144.  
  145.  
  146. /********  user-accessible error handling functions ***************/
  147.  
  148. void  __vf  V_noteError( char _VFAR *fname, unsigned why );
  149. void  __vf  V_printErrorMsg( char _VFAR *ErrMsg );
  150. void  __vf  V_setErrorEventFile( char _VFAR *filename,  unsigned ScreenAndFile );
  151. void  __vf  V_closeErrorEventFile( void );
  152.  
  153.  
  154. #if defined __BORLANDC__
  155.     /*** translation of calls to matherr() into _matherr() for BorlandC 4.0+ ***/
  156.     #if (__BORLANDC__ >= 0x450) && !defined (__FLAT__)
  157.         #if !defined( __MATH_H )
  158.             #include <math.h>
  159.         #endif
  160.         int  _Cdecl _FARFUNC matherr (struct exception _VFAR *__e);
  161.         #define NEWMATHERR  \
  162.             int matherr( struct exception _VFAR *__e ) \
  163.             {  return( _matherr( __e )); }
  164.     #else   /* either FLAT model or older versions of Borland C++ */
  165.         #define NEWMATHERR
  166.     #endif
  167. #else  /* for Visual C++ and Optima++  */
  168.     #define NEWMATHERR
  169. #endif
  170.  
  171.  
  172. /************ Integer OVERFLOW handling **************************/
  173.  
  174. #ifdef V_trapIntError
  175.    typedef enum
  176.    {
  177.          ierrIgnore = 0,
  178.          ierrNote,
  179.          ierrAbort
  180.    }   V_ihand;
  181.  
  182.    void __vf  V_setIntErrorHandling( V_ihand a );
  183. #endif
  184.  
  185. #if defined __cplusplus
  186. }   // end of extern "C" statement
  187. #endif
  188.  
  189.         /*  constructors of complex data types:   */
  190. fComplex __vf fcplx( float    __ReVal, float    __ImVal);
  191. dComplex __vf dcplx( double   __ReVal, double   __ImVal);
  192. #ifdef __BORLANDC__
  193.    eComplex __vf ecplx( extended __ReVal, extended __ImVal);
  194. #else  /* Visual C++, Optima++ */
  195.    #define ecplx dcplx
  196. #endif
  197.      /*  for overloaded constructors and for all "non-vector"
  198.          operations on complex numbers, see CMATH with the
  199.          include-files <newcplx.h> and <cmath.h> !          */
  200.  
  201. #endif  /*  __VECLIB_H  */
  202.